# Contributor: Bart Ribbers <bribbers@disroot.org>
# Maintainer: Bart Ribbers <bribbers@disroot.org>
pkgname=openrct2
pkgver=0.4.11
_pkgver_objects=1.4.4
_pkgver_title_sequences=0.4.6
_pkgver_replays=0.0.79
_pkgver_opensfx=1.0.5
_pkgver_openmsx=1.5
pkgrel=0
pkgdesc="Open-source re-implementation of Roller Coaster Tycoon 2"
# s390x is not supported upstream
arch="all !s390x"
url="https://openrct2.io"
license="GPL-3.0-only"
depends="$pkgname-data"
makedepends="
	cmake
	curl-dev
	flac-dev
	fontconfig-dev
	gtest-dev
	icu-dev
	jansson-dev
	libpng-dev
	libvorbis-dev
	libzip-dev
	mesa-dev
	musl-fts-dev
	ninja
	nlohmann-json
	sdl2-dev
	speexdsp-dev
	unzip
	"
install="$pkgname.post-install"
subpackages="$pkgname-doc $pkgname-cli $pkgname-data::noarch"
source="$pkgname-$pkgver.tar.gz::https://github.com/openrct2/openrct2/archive/refs/tags/v$pkgver.tar.gz
	$pkgname-$_pkgver_title_sequences-title_sequences.zip::https://github.com/OpenRCT2/title-sequences/releases/download/v$_pkgver_title_sequences/title-sequences.zip
	$pkgname-$_pkgver_objects-objects.zip::https://github.com/OpenRCT2/objects/releases/download/v$_pkgver_objects/objects.zip
	$pkgname-$_pkgver_replays-replays.zip::https://github.com/OpenRCT2/replays/releases/download/v$_pkgver_replays/replays.zip
	$pkgname-$_pkgver_opensfx-opensfx.zip::https://github.com/OpenRCT2/OpenSoundEffects/releases/download/v$_pkgver_opensfx/opensound.zip
	$pkgname-$_pkgver_openmsx-openmsx.zip::https://github.com/OpenRCT2/OpenMusic/releases/download/v$_pkgver_openmsx/openmusic.zip
	Werror.patch
	0001-int32_t.patch
	0002-gtest.patch
	0003-disable-version-check.patch
	"
case "$CARCH" in
	arm*) options="!check" ;; # https://github.com/OpenRCT2/OpenRCT2/issues/12727
esac
builddir="$srcdir/OpenRCT2-$pkgver"

prepare() {
	default_prepare

	mkdir -p \
		data/title \
		data/object \
		testdata/replays \
		data/assetpack/openrct2.sound.parkap \
		data/assetpack/openrct2.music.alternative.parkap
	unzip "$srcdir"/$pkgname-$_pkgver_title_sequences-title_sequences.zip -d data/title
	unzip "$srcdir"/$pkgname-$_pkgver_objects-objects.zip -d data/object
	unzip "$srcdir"/$pkgname-$_pkgver_replays-replays.zip -d testdata/replays
	unzip "$srcdir"/$pkgname-$_pkgver_opensfx-opensfx.zip -d data/assetpack/openrct2.sound.parkap
	unzip "$srcdir"/$pkgname-$_pkgver_openmsx-openmsx.zip -d data/assetpack/openrct2.music.alternative.parkap
}

build() {
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=RelWithDebInfo \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=ON \
		-DWITH_TESTS=ON \
		-DDOWNLOAD_TITLE_SEQUENCES=OFF \
		-DDOWNLOAD_OBJECTS=OFF \
		-DDOWNLOAD_REPLAYS=OFF \
		-DDOWNLOAD_OPENSFX=OFF \
		-DDOWNLOAD_OPENMSX=OFF \
		-DDISABLE_GOOGLE_BENCHMARK=ON # Not packaged in Alpine
	cmake --build build
}

check() {
	ln -s "$builddir"/data build/data

	local skipped_tests=""
	local tests="
		replay_tests
		string
		localisation
		enummaptests
		Localisation.RCT2_to_UTF8_JP
		Localisation.RCT2_to_UTF8_ZH_TW
		Localisation.RCT2_to_UTF8_ZH_TW_PREMATURE_END
		RideRatings.BigMap
		StringTest.Convert_950_to_UTF8
		"
	for test in $tests; do
		skipped_tests="$skipped_tests|$test"
	done
	ctest --test-dir build --output-on-failure -E "$skipped_tests"
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

data() {
	amove usr/share/openrct2

	# https://github.com/OpenRCT2/OpenRCT2/issues/12716
	mv "$subpkgdir"/usr/share/openrct2/title \
		"$subpkgdir"/usr/share/openrct2/sequence
}

cli() {
	depends="openrct2-data"
	install="$subpkgname.post-install"

	amove usr/bin/openrct2-cli
}
sha512sums="
820b0aaccdde433bf3da8a45e5893882e7a0bb1b0084fa6130ceab91489584a9d10b1ef18bac718e3f9ea910bdbcd878b7a3ca4f9361663a9fb496bb62a0ca80  openrct2-0.4.11.tar.gz
bd7d0f25047540572be75a4a8886e8dabdceb7a3e11fdeb5473b66fe804d829acdb763d34ec7cfa656df9bc527268a3e0e7ca09c699995804b22ff2a529ad5da  openrct2-0.4.6-title_sequences.zip
602057c184970fa15e7f40804262fca55d21709d403d85b89d6c264144dc4251b9aa058b4ef37b5723c4ea39d6a317f0304fe41f1a9734766a75d1cab1170e75  openrct2-1.4.4-objects.zip
04acde4d60c8fa949b298dd15e38fe0421659357fa214dffb0577574e0b0ac218a01ce998f4e12e3ab13a88fbbba8096392462fda29c68a6215bc0875aaae9b2  openrct2-0.0.79-replays.zip
fc46ffb3f6243b3d783a280481ce373a8ddc8cf1fd28bfeceecf6223b72b38f1d49d0c95eea3376308a61a77c50c7a06252b6d72248cfecc493b63b65bd6512a  openrct2-1.0.5-opensfx.zip
55d4afb854eaa5a69c42e7f0b26669c8fb58b2eba3e2892c655e76d8fab82e2734f39981d7f5ac69e11dc87d06c89795da2468feac3bc53ef6cfdd992e3924f3  openrct2-1.5-openmsx.zip
cd39a38a59b8544d38895255e8719a8c1ca404d56073649c2434db5c4aa121d4f86460cb90e04d16d5da61dff95826de9a634d433087c08dcc4f2222208507b1  Werror.patch
c56151de6ec2f4b9ca279ef038e3c3be87f1a61d6d6ebb1abbddc0aabbd5913aaa88fa724663cd2e2cd3729868b61e727c3dcfd03af5685ed6ca583e16ee0cb3  0001-int32_t.patch
92231018fdfa42bd62bc0318dbd886f01837f655906d14565a1f9af3a7a6d5cde8d09bbb8eeedd904791dfd56d2cc64187ce27bc1333c52bdc028191d696a0c9  0002-gtest.patch
bed74cd3895e5aaeab6865af949d909222b14de6bc42401bf0f787a9924319c6e5b20ce4974d61a4913475c0d169d4062e9cf0656ccb348a2b92f24ca19c3b48  0003-disable-version-check.patch
"
